package maze.levels;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import javax.imageio.ImageIO;
import maze.Game;
import maze.Game.State;

/**
 *
 * @author Dennis Nijssen
 */
public class Question extends BaseTag {
    private Image tagMark;
    private List<String> answers;    
    private boolean visited;
    private int selectedIndex;
    
    public Question(URL imageURL, String question) throws IOException {
        super(imageURL, question);
        
        answers = new LinkedList<String>();
        visited = false;
        
        this.tagMark = ImageIO.read(new URL(Game.baseURL, "ress/Vink.png"));
    }
    
    /**
     * This method initializes a new Answer object and adds this to the 
     * list of answers
     * 
     * @param answer the answer String represents the answer
     */
    public void addAnswer(String answer) {
        answers.add(answer);
    }
    
    public List<String> getAnswers() {
        return answers;
    }
    
    public boolean getVisited() {
        return this.visited;
    }
    
    public String getQuestion() {
        return this.description;
    }

    /*@Override
    public String toString() {
        return getQuestion();
    }*/
    
    @Override
    public void paint(Graphics2D g2d, double x, double y, double scaleX, double scaleY) {
        g2d.drawImage(this.getImage(), (int)(x + 1), (int)(y + 1), (int)(scaleX - 2), (int)(scaleY - 2), null);
        if(visited) {
            g2d.drawImage(this.tagMark, (int)(x + 1), (int)(y + 1), (int)(scaleX - 2), (int)(scaleY - 2), null);
        }
    }
    
    /*public void paintPane(Graphics2D g2d, int width, int height) {        
        // Bepaal de maten van de tekst
        FontMetrics fontMetrics = g2d.getFontMetrics(Game.font);
        Rectangle2D bounds = fontMetrics.getStringBounds(getQuestion(), g2d);
        
        int textX = (int)(width - bounds.getWidth()) / 2;
        int textY = 50;
        
        g2d.setColor(Color.black);
        g2d.setFont(Game.font);
        g2d.drawString(getQuestion(), textX, textY);
        
        for(int i = 0; i < answers.size(); i++) {
            Answer answer = answers.get(i);
            boolean isSelected = i == selectedIndex;
            
            textY += 70;
            answer.paint(g2d, isSelected, textY);
        }
    }
    
    public void moveSelectionUp() {
        selectedIndex--;
        if(selectedIndex < 0) {
            selectedIndex = answers.size() + selectedIndex;
        }
    }
    
    public void moveSelectionDown() {
        selectedIndex++;
        selectedIndex = selectedIndex % answers.size();
    }
    */
    public String getSelectedAnswer() {        
        return answers.get(selectedIndex);
    }
    
    public void selectAnswer(int selectedIndex) {
        this.selectedIndex = selectedIndex;
        Game.STATE = State.GAME;
        this.visited = true;
    }
}
